package com.sasac.test.controller;

import com.sasac.common.core.web.controller.BaseController;
import com.sasac.common.core.web.domain.AjaxResult;
import com.sasac.common.security.annotation.PreAuthorize;
import com.sasac.test.domain.Student;
import com.sasac.test.projection.StudentProjection;
import com.sasac.test.service.IStudentService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * 参数配置 信息操作处理
 *
 * @author sasac
 */
@RestController
@RequestMapping("/my")
public class MyController extends BaseController {


    @Autowired
    IStudentService studentService;

    /**
     * 获取参数配置列表
     */
    @GetMapping("/test")
    @PreAuthorize(hasPermi = "system:user:list")
    public AjaxResult list(String name) {
        return AjaxResult.success(name);
    }


    @RequestMapping(value="/get/{id}")
    public String find(@PathVariable("id") Long id ){
        Student byId = studentService.findById(id);
        return byId.getName();
    }

    @RequestMapping(value="/get/stu/{id}")
    public String findStudentInfo(@PathVariable("id") Long id ){
        StudentProjection studentInfo = studentService.findStudentInfo(id);
        return studentInfo.getId()+studentInfo.getSchoolName()+studentInfo.getStudentName();
    }

    @RequestMapping(value="/get/stu1/{id}")
    public String findStudentInfo1(@PathVariable("id") Long id ){
        Page<StudentProjection> studentInfo1 = studentService.findStudentInfo1(id);
        System.out.println(studentInfo1.getTotalElements());
        System.out.println(studentInfo1.getTotalPages());
        List<StudentProjection> content = studentInfo1.getContent();
        for (StudentProjection studentProjection : content) {
            System.out.println(studentProjection.getId()+studentProjection.getSchoolName()+studentProjection.getStudentName());
        }
        return studentInfo1.toString();
    }


    @RequestMapping(value="/get/stu2/{id}")
    public String findStudentInfo2(@PathVariable("id") Long id ){
        List<StudentProjection> studentInfo1 = studentService.findStudentInfo2(id);
        for (StudentProjection studentInfo : studentInfo1) {
            System.out.println(studentInfo.getId()+studentInfo.getSchoolName()+studentInfo.getStudentName());
        }
        return String.valueOf(studentInfo1.size());
    }

}
